from django import template

register = template.Library()

@register.filter(name='add_attrs')
def add_attributes(field, attrs_str):
    """
    一次性添加多个属性，格式: "class:form-control;rows:6;placeholder:请输入内容"
    """
    attrs = {}
    # 分割多个属性
    for attr in attrs_str.split(';'):
        if ':' in attr:
            key, value = attr.split(':', 1)
            attrs[key.strip()] = value.strip()
    return field.as_widget(attrs=attrs)
